﻿using STT.Debug;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace STT
{
    // Token: 0x0200003B RID: 59
    public class StructFormatView
    {
        // Token: 0x1700002D RID: 45
        // (get) Token: 0x0600012D RID: 301 RVA: 0x0000BE87 File Offset: 0x0000AE87
        // (set) Token: 0x0600012E RID: 302 RVA: 0x0000BE8F File Offset: 0x0000AE8F
        public RichTextBox rich_text_box
        {
            get
            {
                return this.m_rich_text_box;
            }
            set
            {
                this.m_rich_text_box = value;
            }
        }

        // Token: 0x1700002E RID: 46
        // (get) Token: 0x0600012F RID: 303 RVA: 0x0000BE98 File Offset: 0x0000AE98
        public RichTextBox rich_text_box_temp
        {
            get
            {
                return this.m_rich_text_box_temp;
            }
        }

        // Token: 0x06000130 RID: 304 RVA: 0x0000BEA0 File Offset: 0x0000AEA0
        private void Init()
        {
            this.components = new Container();
            this.MenuFlottant = new ContextMenuStrip(this.components);
            this.SelectAll_MenuFlottant = new ToolStripMenuItem();
            this.CopySelectBrut_MenuFlottant = new ToolStripMenuItem();
            this.CopySelectRtf_MenuFlottant = new ToolStripMenuItem();
            this.MenuFlottant.Name = "MenuFlottant";
            this.MenuFlottant.Size = new Size(176, 26);
            this.SelectAll_MenuFlottant.Name = "SelectAll_MenuFlottant";
            this.SelectAll_MenuFlottant.Size = new Size(175, 22);
            this.SelectAll_MenuFlottant.Tag = null;
            this.SelectAll_MenuFlottant.Text = "Select all";
            this.SelectAll_MenuFlottant.Click += this.MenuFlottant_Click;
            this.MenuFlottant.Items.Add(this.SelectAll_MenuFlottant);
            this.CopySelectBrut_MenuFlottant.Name = "CopySelectBrut_MenuFlottant";
            this.CopySelectBrut_MenuFlottant.Size = new Size(175, 22);
            this.CopySelectBrut_MenuFlottant.Tag = null;
            this.CopySelectBrut_MenuFlottant.Text = "Brut copy";
            this.CopySelectBrut_MenuFlottant.Click += this.MenuFlottant_Click;
            this.MenuFlottant.Items.Add(this.CopySelectBrut_MenuFlottant);
            this.CopySelectRtf_MenuFlottant.Name = "CopySelectRtf_MenuFlottant";
            this.CopySelectRtf_MenuFlottant.Size = new Size(175, 22);
            this.CopySelectRtf_MenuFlottant.Tag = null;
            this.CopySelectRtf_MenuFlottant.Text = "Rtf copy";
            this.CopySelectRtf_MenuFlottant.Click += this.MenuFlottant_Click;
            this.MenuFlottant.Items.Add(this.CopySelectRtf_MenuFlottant);
            this.rich_text_box = new RichTextBox();
            this.rich_text_box.WordWrap = false;
            this.rich_text_box.Font = new Font(FontFamily.GenericMonospace, 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.rich_text_box.ReadOnly = true;
            this.rich_text_box.BackColor = Color.White;
            this.m_rich_text_box_temp = null;
            this.rich_text_box.ContextMenuStrip = this.MenuFlottant;
        }

        // Token: 0x06000131 RID: 305 RVA: 0x0000C0CC File Offset: 0x0000B0CC
        public void CreateTemp()
        {
            this.m_rich_text_box_temp = new RichTextBox();
            this.rich_text_box_temp.WordWrap = false;
            this.rich_text_box_temp.Font = new Font(FontFamily.GenericMonospace, 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.rich_text_box_temp.ReadOnly = true;
            this.rich_text_box_temp.BackColor = Color.White;
            this.rich_text_box_temp.ContextMenuStrip = this.MenuFlottant;
        }

        // Token: 0x06000132 RID: 306 RVA: 0x0000C13A File Offset: 0x0000B13A
        public StructFormatView(Control _control_parent)
        {
            this.m_rich_text_box_temp = null;
            this.control_parent = _control_parent;
            this.Init();
            this.Active();
        }

        // Token: 0x06000133 RID: 307 RVA: 0x0000C15C File Offset: 0x0000B15C
        public void Active()
        {
            if (this.rich_text_box_temp != null)
            {
                this.rich_text_box = this.rich_text_box_temp;
                this.m_rich_text_box_temp = null;
            }
            this.rich_text_box.Visible = false;
            this.control_parent.Controls.Clear();
            this.control_parent.Controls.Add(this.rich_text_box);
            this.rich_text_box.Dock = DockStyle.Fill;
            this.rich_text_box.Visible = true;
        }

        // Token: 0x06000134 RID: 308 RVA: 0x0000C1CE File Offset: 0x0000B1CE
        public void AddLine(string s)
        {
            this.rich_text_box.AppendText(s + "\n");
        }

        // Token: 0x06000135 RID: 309 RVA: 0x0000C1E8 File Offset: 0x0000B1E8
        public void DisplayFormatView(string s)
        {
            if (s != null)
            {
                s = s.Replace("\r\n", "\n");
            }
            if (this.rich_text_box_temp != null)
            {
                this.rich_text_box_temp.Text = s;
                return;
            }
            if (!string.IsNullOrEmpty(s))
            {
                this.Init();
            }
            this.rich_text_box.Text = s;
        }

        // Token: 0x06000136 RID: 310 RVA: 0x0000C23C File Offset: 0x0000B23C
        private void MenuFlottant_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem toolStripMenuItem = (ToolStripMenuItem)sender;
            if (toolStripMenuItem == this.SelectAll_MenuFlottant)
            {
                this.rich_text_box.SelectAll();
                this.rich_text_box.Show();
                return;
            }
            if (toolStripMenuItem == this.CopySelectBrut_MenuFlottant)
            {
                if (!string.IsNullOrEmpty(this.rich_text_box.SelectedText))
                {
                    Clipboard.SetText(this.rich_text_box.SelectedText, TextDataFormat.Text);
                    return;
                }
            }
            else if (toolStripMenuItem == this.CopySelectRtf_MenuFlottant && !string.IsNullOrEmpty(this.rich_text_box.SelectedRtf))
            {
                Clipboard.SetText(this.rich_text_box.SelectedRtf, TextDataFormat.Rtf);
            }
        }

        // Token: 0x06000137 RID: 311 RVA: 0x0000C2C9 File Offset: 0x0000B2C9
        public bool FindNextString(DialogBoxFind.RequestFindText request_scan)
        {
            return this.FindStringByStartIndex(request_scan, this.rich_text_box.SelectionStart + 1);
        }

        // Token: 0x06000138 RID: 312 RVA: 0x0000C2DF File Offset: 0x0000B2DF
        public bool FindString(DialogBoxFind.RequestFindText request_scan)
        {
            return this.FindStringByStartIndex(request_scan, this.rich_text_box.SelectionStart);
        }

        // Token: 0x06000139 RID: 313 RVA: 0x0000C2F4 File Offset: 0x0000B2F4
        private bool FindStringByStartIndex(DialogBoxFind.RequestFindText request_scan, int StartIndex)
        {
            if (!string.IsNullOrEmpty(this.rich_text_box.Text) && !string.IsNullOrEmpty(request_scan.word_regex))
            {
                string str = Regex.Escape(request_scan.word_regex);
                string text = "(" + str + ")";
                string pattern = "(^|\\s+)(" + text + ")(\\s+|$)";
                Regex regex = new Regex(text, RegexOptions.IgnoreCase);
                Regex regex2 = new Regex(text);
                Regex regex3 = new Regex(pattern, RegexOptions.IgnoreCase);
                Regex regex4 = new Regex(pattern);
                Regex regex5 = regex2;
                if (request_scan.flag_use_regex)
                {
                    Match match = regex5.Match(this.rich_text_box.Text, StartIndex);
                    if (match.Success)
                    {
                        this.rich_text_box.Select(match.Index, match.Length);
                        Interaction.DisplayViewerPanel();
                        this.rich_text_box.Focus();
                        return true;
                    }
                }
                else
                {
                    if (request_scan.flag_match_whole_text)
                    {
                        if (request_scan.flag_match_case)
                        {
                            regex5 = regex4;
                        }
                        else
                        {
                            regex5 = regex3;
                        }
                    }
                    else if (!request_scan.flag_match_case)
                    {
                        regex5 = regex;
                    }
                    Match match = regex5.Match(this.rich_text_box.Text, StartIndex);
                    if (match.Success)
                    {
                        if (request_scan.flag_match_whole_text)
                        {
                            if (request_scan.flag_match_case)
                            {
                                regex5 = regex2;
                            }
                            else
                            {
                                regex5 = regex;
                            }
                            match = regex5.Match(this.rich_text_box.Text, match.Index, match.Length);
                        }
                        this.rich_text_box.Select(match.Index, match.Length);
                        Interaction.DisplayViewerPanel();
                        this.rich_text_box.Focus();
                        return true;
                    }
                }
            }
            return false;
        }

        // Token: 0x040001A9 RID: 425
        private ContextMenuStrip MenuFlottant;

        // Token: 0x040001AA RID: 426
        private IContainer components;

        // Token: 0x040001AB RID: 427
        private ToolStripMenuItem SelectAll_MenuFlottant;

        // Token: 0x040001AC RID: 428
        private ToolStripMenuItem CopySelectBrut_MenuFlottant;

        // Token: 0x040001AD RID: 429
        private ToolStripMenuItem CopySelectRtf_MenuFlottant;

        // Token: 0x040001AE RID: 430
        private RichTextBox m_rich_text_box;

        // Token: 0x040001AF RID: 431
        private RichTextBox m_rich_text_box_temp;

        // Token: 0x040001B0 RID: 432
        private Control control_parent;
    }
}